/* \$Id: common.js 448 2012-07-05 23:16:54Z bobcat $ */

var J = jQuery.noConflict();

/**
 * @license Email obfuscator script 2.1 by Tim Williams, University of Arizona
 * Random encryption key feature by Andrew Moulden, Site Engineering Ltd
 * This code is freeware provided these four comment lines remain intact
 * A wizard to generate this code is at http://www.jottings.com/obfuscator/
 */
function drawReportBugLink() {
  var coded, key, shift, link, i, ltr;
  coded = '36SS.oxoGKa@4QKnq.GxQ';
  key = 'WSCBlG2zjVg8xAptvHeNmiruTq0LhPd4b519aDIEsQnZ67cUMfO3woXkRKYyJF';
  shift = coded.length;
  link = '';
  for (i = 0; i < coded.length; i += 1) {
    if (key.indexOf(coded.charAt(i)) === -1) {
      ltr = coded.charAt(i);
      link += (ltr);
    }
    else {
      ltr = (key.indexOf(coded.charAt(i)) - shift + key.length) % key.length;
      link += (key.charAt(ltr));
    }
  }
  J('div.report').html("<a href='mailto:" + link + '?subject=DSC Bug - ' +
      window.location.pathname + window.location.search + "'>Report a Bug</a>");
}

function loginNotice() {
  if (getURLParameter('login') == 'true') {
    J('#notice').delay(1000).fadeIn('fast').delay(6000).fadeOut('fast');
  }
}

function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}

// pop up an error if something goes wrong
function handleError(message, error) {
  alert(message + ' : ' + error);
}

// set up cart configuration for UC JS API
var cartConfig = {
  merchantId: 'TMCSC',
  screenBrandingThemeCode: 'DSC',
  isCheckoutPage: false,
  checkoutSite: 'www.datastoragecables.com',
  remoteApiUrl: 'https://www.datastoragecables.com' +
      '/cgi-bin/UCCheckoutAPIJSON',
  debugMode: false,
  verboseAjax: false
};

J(document).ready(function() {
  drawReportBugLink();
  loginNotice();

  // remove default text from input on focus
  J('input[type="text"][class!="ucFormField"]').focus(function() {
    if (J(this).val() === J(this).attr('title')) {
      J(this).val('');
    }
  });

  // replace default text in input on blur
  J('input[type="text"][class!="ucFormField"]').blur(function() {
    if (J(this).val() === '') {
      J(this).val(J(this).attr('title'));
    }
  });

});
